<?php
/*
 * @Date: 2025-03-29 16:38:22
 * @LastEditors: 贾二小 erxiao.jia@outlook.com
 * @LastEditTime: 2025-04-10 22:33:37
 * @FilePath: /admin-laravel/database/migrations/0001_01_01_000000_create_users_table.php
 */

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('unionid')->nullable()->comment('微信开放平台unionid');
            $table->string('openid')->nullable()->comment('微信openid');
            $table->string('avatar')->nullable()->comment('头像');
            $table->string('mobile', 20)->unique()->comment('电话号码');
            $table->string('email', 100)->unique()->nullable()->comment('邮件地址');
            $table->string('name', 50)->comment('昵称');
            $table->string('real_name', 50)->nullable()->comment('真实姓名');
            $table->enum('sex', ['男', '女', '保密'])->default('保密')->comment('性别');
            $table->boolean('is_super_admin')->default(false)->comment('是否是超级管理员');
            $table->unsignedInteger('login_count')->default(0)->comment('登录次数');
            $table->timestamp('email_verified_at')->nullable()->comment('邮件验证时间');
            $table->timestamp('mobile_verified_at')->nullable()->comment('手机验证时间');
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
            $table->softDeletes();
        });

        Schema::create('password_reset_tokens', function (Blueprint $table) {
            $table->string('email')->primary();
            $table->string('token');
            $table->timestamp('created_at')->nullable();
        });

        Schema::create('sessions', function (Blueprint $table) {
            $table->string('id')->primary();
            $table->foreignId('user_id')->nullable()->index();
            $table->string('ip_address', 45)->nullable();
            $table->text('user_agent')->nullable();
            $table->longText('payload');
            $table->integer('last_activity')->index();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('users');
        Schema::dropIfExists('password_reset_tokens');
        Schema::dropIfExists('sessions');
    }
};
